package com.team.recruitment_management_system.controller;

import com.team.recruitment_management_system.pojo.dto.auth.EmailAndCaptchaDto;
import com.team.recruitment_management_system.pojo.dto.user.AddUserInfoDto;
import com.team.recruitment_management_system.pojo.dto.user.ChangeEmailDto;
import com.team.recruitment_management_system.pojo.dto.user.ChangePwdDto;
import com.team.recruitment_management_system.pojo.vo.UserInfoVo;
import com.team.recruitment_management_system.security.OperationLogAnnotation;
import com.team.recruitment_management_system.service.SysUserRoleService;
import com.team.recruitment_management_system.service.SysUserService;
import com.team.recruitment_management_system.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Tag(name = "3.用户模块")
public class UserController {
    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private SysUserRoleService sysUserRoleService;

    @OperationLogAnnotation(operModul = "用户模块-原密码修改密码", operType = "修改", operDesc = "put请求，原密码修改密码")
    @Operation(summary = "原密码修改密码")
    @PutMapping("/pwd/ByOld")
    public Result<Void> changePassword(@RequestBody @Validated ChangePwdDto changePwdDto, @RequestHeader String Authorization) {
        return sysUserService.changePassword(changePwdDto, Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-绑定邮箱", operType = "添加", operDesc = "post请求，绑定邮箱")
    @Operation(summary = "绑定邮箱")
    @PostMapping("/email")
    public Result<Void> bindingEmail(@RequestBody @Validated EmailAndCaptchaDto emailAndCaptchaDto, @RequestHeader String Authorization) {
        return sysUserService.bindingEmail(emailAndCaptchaDto, Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-验证旧邮箱", operType = "查询", operDesc = "post请求，验证旧邮箱")
    @Operation(summary = "验证旧邮箱")
    @PostMapping("/oldEmail")
    public Result<Void> verifyOldEmail(@RequestBody @Validated EmailAndCaptchaDto emailAndCaptchaDto, @RequestHeader String Authorization) {
        return sysUserService.verifyOldEmail(emailAndCaptchaDto, Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-修改邮箱", operType = "修改", operDesc = "put请求，修改邮箱")
    @Operation(summary = "修改邮箱")
    @PutMapping("/email")
    public Result<Void> changeEmail(@RequestBody @Validated ChangeEmailDto changeEmailDto, @RequestHeader String Authorization) {
        return sysUserService.changeEmail(changeEmailDto, Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-绑定或修改电话", operType = "修改", operDesc = "put请求，绑定或修改电话")
    @Operation(summary = "绑定或修改电话")
    @PutMapping("/phone")
    public Result<Void> changePhone(String phone, @RequestHeader String Authorization) {
        return sysUserService.changePhone(phone, Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-修改头像", operType = "修改", operDesc = "put请求，修改头像")
    @Operation(summary = "修改头像")
    @PutMapping("/avatar")
    public Result<Void> changeAvatar(String avatar, @RequestHeader String Authorization) {
        return sysUserService.changeAvatar(avatar, Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-注销账号", operType = "删除", operDesc = "delete请求，注销账号")
    @Operation(summary = "注销账号")
    @DeleteMapping("/one")
    public Result<Void> cancelAccount(@RequestHeader String Authorization) {
        return sysUserService.cancelAccount(Authorization);
    }

//    @OperationLogAnnotation(operModul = "用户模块-获取个人信息", operType = "查询", operDesc = "get请求，查询单个用户信息")
    @Operation(summary = "获取个人信息")
    @GetMapping("/one")
    public Result<UserInfoVo> getUserInfo(@RequestHeader String Authorization) {
        return sysUserService.getUserInfo(Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-添加用户信息", operType = "添加", operDesc = "post请求，添加用户信息")
    @Operation(summary = "添加用户信息")
    @PostMapping("/one")
    public Result<Void> add(@RequestBody AddUserInfoDto addUserInfoDto, @RequestHeader String Authorization) {
        return sysUserService.addUserInfo(addUserInfoDto,Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-添加求职者角色", operType = "添加", operDesc = "post请求，添加求职者角色")
    @Operation(summary = "添加求职者角色")
    @PostMapping("/seeker")
    public Result<Void> addUserSeekerRole(@RequestHeader String Authorization) {
        return sysUserRoleService.addUserSeekerRole(Authorization);
    }

    @OperationLogAnnotation(operModul = "用户模块-添加HR角色", operType = "添加", operDesc = "post请求，添加HR角色")
    @Operation(summary = "添加HR角色")
    @PostMapping("/HR")
    public Result<Void> addUserHRRole(@RequestHeader String Authorization) {
        return sysUserRoleService.addUserHRRole(Authorization);
    }
}
